package com.example.demo;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class PlayListAdapter extends RecyclerView.Adapter<PlayListAdapter.ViewHolder> {
    ArrayList<PlayItem> list = new ArrayList();

    public static class PlayItem {
        String name;
        String time;

        public PlayItem(String name, String time) {
            this.name = name;
            this.time = time;
        }
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        PlayItem item = list.get(position);
        holder.nameView.setText(item.name);
        holder.timeView.setText(item.time);
    }

    public void setData(ArrayList<PlayItem> list) {
        this.list = list;
    }

    public void addItem(PlayItem item) {
        list.add(item);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_layout, null);
        return new ViewHolder(view);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView nameView;
        TextView timeView;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            nameView = itemView.findViewById(R.id.tx_name_id);
            timeView = itemView.findViewById(R.id.tx_date_id);
        }
    }
}
